<template> <div style="
  height: 2160px;
margin:0px;margin-top: -100px;
background: url(3.jpg) no-repeat;
background-size:100% 100%;
background-attachment:fixed;position: relative;overflow: hidden;color: black" >
  <el-card style="width: 530px;height: 340px;margin: 300px auto!important;margin-left: 500px!important;
                background-color: rgba(255,255,255,0.5); float: left;color:black;" >
    <div slot="header" class="clearfix">
      <span>用户注册界面</span>
    </div>
    <div class="text item">
      <el-form :model="user" :rules="rules" ref="user" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名" prop="phone">
          <el-input v-model="user.phone"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="user.password" show-password></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('user')">注册</el-button>
          <el-button type="primary" @click="resetForm()">去登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-card>
</div>
</template>

<script>
export default {
  data() {
    return {
      user: {
        phone: '',
        password: ''
      },
      rules: {
        phone: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let user = this.qs.stringify(this.user)
          let url = 'http://localhost:8080/userreg/reg';
          this.axios.post(url, user).then((response) => {
            let responseBody = response.data;
            if (responseBody.state == 20000) {
              alert('注册成功!');
              location.href="/userlogin";
            } else {
              this.$message({
                type: 'info',
                message: responseBody.message
              });
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm() {
      location.href = "/userlogin"
    }
  },
}
</script>

<style>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}


</style>